<template>
  <div v-if="order">
    <Header head="订单详情" />
    <div class="head">
      <img :src="'https://elm.cangdu.org/img/'+order._doc.restaurant_image_url" alt />
      <p v-text="order._doc.status_bar.title"></p>
      <router-link :to="'/shop?id='+order._doc.restaurant_id" class="button">再来一单</router-link>
    </div>
    <div class="menu">
      <router-link to>
        <img :src="'https://elm.cangdu.org/img/'+order._doc.restaurant_image_url" alt />
        <span class="title">{{order._doc.restaurant_name}}</span>
        <a href @click.prevent class="right mui-icon mui-icon-arrowright"></a>
      </router-link>
      <ul class="list">
        <li v-for="(item, index) in order._doc.basket.group" :key="index">
          <p>{{item[0].name}}</p>
          <div>
            <span>x{{item[0].quantity}}</span>
            <span>￥{{item[0].price}}</span>
          </div>
        </li>
      </ul>
      <div class="deliver_fee ls_">
        <span>{{order._doc.basket.deliver_fee.name}}</span>
        <span>{{order._doc.basket.deliver_fee.price}}</span>
      </div>
    </div>
    <div class="ls_">
      <span class="title">配送信息</span>
    </div>
    <div class="msg">
      <p>送达时间：</p>
      <p>{{order.deliver_time}}</p>
    </div>
    <div class="address">
      <p>送货地址：</p>
      <div>
        <p>{{order.consignee}}</p>
        <p>{{order.phone}}</p>
        <p>{{order.addressDetail}}</p>
      </div>
    </div>
    <div class="ls_">
      <span class="title">订单信息</span>
    </div>
    <div class="msg">
      <p>订单号：</p>
      <p>{{order._doc.id}}</p>
    </div>
    <div class="pay_method">
      <p>支付方式：</p>
      <p>{{order.pay_method}}</p>
    </div>
    <div class="pay_method">
      <p>下单时间：</p>
      <p>{{order._doc.formatted_created_at}}</p>
    </div>
  </div>
</template>

<script>
import Header from '../common/Header'
import { Toast } from 'mint-ui'
export default {
  components: {
    Header
  },
  data() {
    return {
      order: null
    }
  },
  methods: {
    getOrderDe() {
      let userid = JSON.parse(localStorage.getItem('user')).user_id
      this.$http
        .get(
          `https://elm.cangdu.org/bos/v1/users/${userid}/orders/${this.$route.query.id}/snapshot`
        )
        .then(data => {
          this.order = data.body
          //window.console.log(this.order)
        })
        .catch(() => {
          window.history.go(-1)
          Toast({
            message: '请求失败,请检查网络连接!',
            duration: 1000
          })
        })
    }
  },
  created() {
    this.getOrderDe()
  }
}
</script>
<style  scoped>
* {
  padding: 0;
  margin: 0;
}
.head {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.head > img {
  border-radius: 50%;
  width: 4rem;
  height: 4rem;
  background-color: red;
}
.head > p {
  text-align: center;
  color: black;
  font-weight: bold;
}
.head > div:last-child {
  display: flex;
  justify-content: center;
  padding: 5vw 0;
}
.button {
  border-radius: 0.3rem;
  font-size: 0.7rem;
  padding: 0 0.3rem;
  border: 1px #26a2ff solid;
  margin: 0 auto;
}
.menu,
.address,
.head {
  border-bottom: 5vw #f5f5f5 solid !important;
}
.menu > a:first-child {
  display: block;
  padding: 0.3rem 1rem;
  border-bottom: 1px #f5f5f5 solid;
}
.menu > a:first-child > img {
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  margin-right: 1rem;
}
.title {
  color: black;
  font-weight: bold;
}
.right {
  float: right;
  color: black;
  opacity: 0.7;
}
.menu li,
.msg,
.address,
.pay_method {
  border-bottom: 1px #f5f5f5 solid;
  display: flex;
  padding: 0.3rem 1rem;
}
.menu li p,
.msg > p,
.address p,
.pay_method p {
  font-size: 0.7rem;
  height: 1.5rem;
  line-height: 1.5rem;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.menu li > div {
  width: 3rem;
  margin-left: 0.5rem;
}
.menu li > div > span {
  font-size: 0.7rem;
  line-height: 1.5rem;
  height: 1.5rem;
  display: block;
}
.menu li > div > span:last-child {
  float: right;
}
.menu li > div > span:first-child {
  float: left;
  color: grey;
}
.ls_ {
  border-bottom: 1px #f5f5f5 solid;
  padding: 0.3rem 1rem;
  overflow: hidden;
}
.deliver_fee > span {
  font-size: 0.7rem;
  line-height: 1.5rem;
  height: 1.5rem;
  display: block;
  float: left;
}
.deliver_fee > span:first-child {
  float: left;
}
.deliver_fee > span:last-child {
  float: right;
}
.msg {
  display: flex;
}
</style>